package jvm;

import java.lang.ref.WeakReference;

/**
 * @Author Stringzhua
 * @Date 2024/11/6 16:22
 * description:
 */
public class Demo05 {
    public static void main(String[] args) {
        String str = new String("abc");

        WeakReference<String> weakReference = new WeakReference<>(str);
        str = null;
        //通知gc回收
        System.gc();
        //一旦发生gc垃圾回收，弱引用一定会被回收
        System.out.println(weakReference.get());
    }
}
